package de.fhdw.seminar.xtext.serializer;

import com.google.inject.Inject;
import com.google.inject.Provider;
import de.fhdw.seminar.xtext.services.UmlDslGrammarAccess;
import de.fhdw.seminar.xtext.umlDsl.UmlAssociation;
import de.fhdw.seminar.xtext.umlDsl.UmlAttribute;
import de.fhdw.seminar.xtext.umlDsl.UmlClass;
import de.fhdw.seminar.xtext.umlDsl.UmlDslPackage;
import de.fhdw.seminar.xtext.umlDsl.UmlModel;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.serializer.acceptor.ISemanticSequenceAcceptor;
import org.eclipse.xtext.serializer.diagnostic.ISemanticSequencerDiagnosticProvider;
import org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic.Acceptor;
import org.eclipse.xtext.serializer.sequencer.AbstractDelegatingSemanticSequencer;
import org.eclipse.xtext.serializer.sequencer.GenericSequencer;
import org.eclipse.xtext.serializer.sequencer.ISemanticSequencer;
import org.eclipse.xtext.serializer.sequencer.ITransientValueService;

@SuppressWarnings("all")
public class UmlDslSemanticSequencer extends AbstractDelegatingSemanticSequencer {

	@Inject
	private UmlDslGrammarAccess grammarAccess;
	
	public void createSequence(EObject context, EObject semanticObject) {
		if(semanticObject.eClass().getEPackage() == UmlDslPackage.eINSTANCE) switch(semanticObject.eClass().getClassifierID()) {
			case UmlDslPackage.UML_ASSOCIATION:
				if(context == grammarAccess.getUmlAssociationRule()) {
					sequence_UmlAssociation(context, (UmlAssociation) semanticObject); 
					return; 
				}
				else break;
			case UmlDslPackage.UML_ATTRIBUTE:
				if(context == grammarAccess.getUmlAttributeRule()) {
					sequence_UmlAttribute(context, (UmlAttribute) semanticObject); 
					return; 
				}
				else break;
			case UmlDslPackage.UML_CLASS:
				if(context == grammarAccess.getUmlClassRule()) {
					sequence_UmlClass(context, (UmlClass) semanticObject); 
					return; 
				}
				else break;
			case UmlDslPackage.UML_MODEL:
				if(context == grammarAccess.getUmlModelRule()) {
					sequence_UmlModel(context, (UmlModel) semanticObject); 
					return; 
				}
				else break;
			}
		if (errorAcceptor != null) errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
	}
	
	/**
	 * Constraint:
	 *     (name=ID type=[UmlClass|ID] isMany?='*'?)
	 */
	protected void sequence_UmlAssociation(EObject context, UmlAssociation semanticObject) {
		genericSequencer.createSequence(context, semanticObject);
	}
	
	
	/**
	 * Constraint:
	 *     (name=ID type=BuiltInTypes isMany?='*'?)
	 */
	protected void sequence_UmlAttribute(EObject context, UmlAttribute semanticObject) {
		genericSequencer.createSequence(context, semanticObject);
	}
	
	
	/**
	 * Constraint:
	 *     (isAbstract?='abstract'? name=ID superType=[UmlClass|ID]? (associations+=UmlAssociation | attributes+=UmlAttribute)*)
	 */
	protected void sequence_UmlClass(EObject context, UmlClass semanticObject) {
		genericSequencer.createSequence(context, semanticObject);
	}
	
	
	/**
	 * Constraint:
	 *     classes+=UmlClass*
	 */
	protected void sequence_UmlModel(EObject context, UmlModel semanticObject) {
		genericSequencer.createSequence(context, semanticObject);
	}
}
